
<!doctype html>
<html class="no-js" lang="">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <title>Untitled Document</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link rel="apple-touch-icon" href="apple-touch-icon.png">
    <!-- Place favicon.ico in the root directory -->

    <link rel="stylesheet" type="text/css" href="../../css/reset.css">
</head>

<body>
    <div class="loading">
        <span class="loadImg"></span>
    </div>
    <div class="prcClass">
        <div class="info">
            <ul>
                <li class="top">
                    <span class="id">id</span>
                    <span class="name">名称</span>
                    <span class="logo none">名称</span>
                    <span class="status">状态</span>
                    <span class="sort">排序</span>
                    <span class="desc none">描述</span>
                    <span class="click">操作</span>
                </li>
            </ul>
        </div>
    </div>
    <div class="revise">
            <div class="prcAddClass">
                <div class="info inputList">
                    <p><span>类型名称：</span><input type="text" class="t1 mel" name=""></p>
                    <!-- <p><span>类型logo：</span><input type="text" class="t2 log" name=""></p> -->
                    <p><span>类型状态：</span>
                        <select class="t3">
                            <option value="1">显示</option>
                            <option value="2">隐藏</option>
                        </select>
                    </p>
                    <p><span>类型排序：</span><input type="text" class="t4 sol" name=""></p>
                    <div class="text"><span>类型描述：</span>
                        <textarea id="text" class="t5 log" ></textarea>
                    </div>
                    <p><button class="addClick">确认</button></p>   
                </div>
            </div>
        </div>
</body>
<script src="../../js/jquery.js"></script>
<script src="../../js/jquery.cookie.js"></script>
<script type="text/javascript" src="../../js/nicEdit.js"></script>
<script type="text/javascript">
    bkLib.onDomLoaded(function() { nicEditors.allTextAreas() });
</script>
<script type="text/javascript">
    $(function(){
            
            getData();

            function getData(){
                var admintoken=$.cookie('admintoken');
                if(admintoken!=null){
                    $('.loading').show();
                    $.ajax({
                        type: 'get',
                        url:'http://www.math80.com/goods/type?_sort=-id',
                        headers:{Authorization:"Bearer "+admintoken},
                        success:function(data){
                            var all=data.data;
                            var len=data.data.length;
                            for(var i=0;i<len;i++){
                                var status='显示';
                                if(all[i].type_status!=1){
                                    status='隐藏';
                                }
                                var li="<li>"+
                                            "<span class='id'>"+all[i].id+"</span>"+
                                            "<span class='logo none'>"+all[i].type_logo+"</span>"+
                                            "<span class='name'>"+all[i].type_name+"</span>"+
                                            "<span class='status'>"+status+"</span>"+
                                            "<span class='sort'>"+all[i].type_sort+"</span>"+
                                            "<span class='desc none'>"+all[i].type_desc+"</span>"+
                                            "<span class='click'>修改</span>"+
                                        "</li>";
                                $('.info ul').append(li);
                                
                            }
                            $('.loading').hide();
                        }
                    })
                }   
            };
            

            var id=null;
            $(document).on('click','.click',function(){

                id=$(this).parent().find('.id').html();
                var name=$(this).parent().find('.name').html();
                var logo=$(this).parent().find('.logo').html();
                var status=$(this).parent().find('.status').html();
                var sort=$(this).parent().find('.sort').html();
                var desc=$(this).parent().find('.desc').html();

                $('.prcAddClass .t1').val(name);
                $('.prcAddClass .t2').val(logo);
                if(status!='显示'){
                    status=2
                }else{
                    status=1
                };
                $('.prcAddClass .t3').val(status);
                $('.prcAddClass .t4').val(sort);
                //$('.prcAddClass .t5').val(desc);
                $('.nicEdit-main').html(desc);

                
            });

            //点击修改
            $('.addClick').click(function(){
                var admintoken=$.cookie('admintoken');
                if(admintoken!=null&&id!=null){
                    var n_name=$('.t1').val();
                    var n_logo=$('.t2').val();
                    var n_status=$('.t3').val();
                    var n_sort=$('.t4').val();
                    var n_desc=nicEditors.findEditor('text').getContent();


                    var data={
                        type_name:n_name,
                        type_logo:n_logo,
                        type_status:n_status,
                        type_sort:n_sort,
                        type_desc:n_desc
                    };
                    $('.loading').show();
                    $.ajax({
                        type: 'put',
                        url:'http://www.math80.com/goods/type/'+id,
                        headers:{Authorization:"Bearer "+admintoken},
                        data:data,
                        success:function(data){
                            $('.loading').hide();
                            getData()
                        }
                    })   
                }else{
                    alert("重新登录")
                }
                
            })

            //取消修改
            $('.close').click(function(){
                $('.inputList input').val('');
                $('.inputList img').attr('src','');
                $('.nicEdit-main').html('');
                id=null;
            })

    })

</script>
</html>